package com.gridmobi.xrtb.model.rtb;


import java.nio.charset.Charset;

/**
 *
 */

public class AdJsTemplate {
    private static String jsAD = "" +
            "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" +
            "<html>" +
            "<head>" +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" +
            "    <meta http-equiv=\"Pragma\" content=\"no-cache\">" +
            "    <meta http-equiv=\"Cache-Control\" content=\"no-cache\">" +
            "    <meta http-equiv=\"Expires\" content=\"0\">" +
            "    <meta content=\"always\" name=\"referrer\">" +
            "    <title></title>" +
            "    <script type=\"text/javascript\">function funtz() {" +
            "        var u = '__TRACKURL__';" +
            "        location.replace(u);" +
            "    }" +
            "" +
            "    function ddl() {" +
            "        var img = document.createElement('img');" +
            "        img.src = '__LANDURL__';" +
            "    }" +
            "" +
            "    setTimeout(ddl, 1);" +
            "    setTimeout(funtz, 80);</script>" +
            "    <noscript>" +
            "        <meta http-equiv=\"refresh\"" +
            "              content=\"0;url=__TRACKURL__\">" +
            "    </noscript>" +
            "</head>" +
            "<body></body>" +
            "</html>";

    public static String jsAd(String adLandUrl,String  rtbLandUrl) {
        String js = jsAD.replaceAll("__LANDURL__", rtbLandUrl).replaceAll("__TRACKURL__", adLandUrl);
        return js;
    }
    public static byte[] jsAd(String adLandUrl,String  rtbLandUrl,String charset) {
        String js = jsAD.replaceAll("__LANDURL__", rtbLandUrl).replaceAll("__TRACKURL__", adLandUrl);

        return js.getBytes(Charset.forName(charset));
    }
    public static void main(String[] args) {
        System.out.println(jsAd("http://www.baidu.com","http://www.jd.com"));
    }
}

